/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sismol.embarcado;

import java.awt.TextArea;
import java.text.DecimalFormat;
import javax.swing.JTextField;
import sismol.cartography.Posicao;

/**
 *
 * @author Rafael
 */
public class GUIWriter {

    private TextArea msgTextArea = null;
    private JTextField textLat = null;
    private JTextField textLong = null;
    private JTextField textVel = null;

    public void writeGUI(String text, Posicao p) throws NullPointerException {
        String currentText = this.msgTextArea.getText();
        if (currentText.length() < 6800 && currentText.length() > 1) {
            this.msgTextArea.setText(currentText.concat("\n" + text));
            this.msgTextArea.setCaretPosition(this.msgTextArea.getText().length());
        } else {
            this.msgTextArea.setText(text);
        }
        DecimalFormat coordFormatter = new DecimalFormat("##.######");
        this.textLat.setText(coordFormatter.format(p.getPosicao().getLatitude()));
        this.textLong.setText(coordFormatter.format(p.getPosicao().getLongitude()));

        DecimalFormat velFormatter = new DecimalFormat("##.#");
        this.textVel.setText(velFormatter.format(p.getVelocidadeMedia()) + " Km/h");
    }

    public void setMsgTextArea(TextArea textArea) {
        this.msgTextArea = textArea;
    }

    public TextArea getMsgTextArea() {
        return this.msgTextArea;
    }

    public JTextField getTextLat() {
        return textLat;
    }

    public void setTextLat(JTextField textLat) {
        this.textLat = textLat;
    }

    public JTextField getTextLong() {
        return textLong;
    }

    public void setTextLong(JTextField textLong) {
        this.textLong = textLong;
    }

    public JTextField getTextVel() {
        return textVel;
    }

    public void setTextVel(JTextField textVel) {
        this.textVel = textVel;
    }
}
